import "./index.less";
import { useEffect, useRef, useState } from "react";

import JoyStick from "../../unit/joyStick";
import Loading from "../../unit/loading";
import audios from "../../assets/audios";

let timer;
export default () => {
  // const bgm: any = useRef();
  // useEffect(() => {
  //   bgm.current.volume = 0.3;
  //   console.log("load home");
  // }, []);

  const [count, setCount] = useState(10);
  useEffect(() => {
    setInterval((count) => {
      let value = count - 1;
      console.log("value", value);
      if (!value) {
        return destroy();
      }
      setCount(value);
    }, 1000);
    return () => {
      destroy();
    };
  }, []);

  function destroy() {
    clearInterval(timer);
    // 其他销毁事件
  }
  console.log("time", count);
  return (
    <div className="home">
      <Loading />
      <JoyStick />
      {/* <audio ref={bgm} src={audios.song} loop autoPlay /> */}
    </div>
  );
};
